package com.budwk.app.miniapp.services.impl;

import com.budwk.starter.common.page.PageUtil;
import com.budwk.starter.database.service.BaseServiceImpl;
import com.budwk.app.miniapp.models.WxArea;
import com.budwk.app.miniapp.services.WxareaService;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;

@IocBean(args = {"refer:dao"})
public class WxareaServiceImpl extends BaseServiceImpl<WxArea> implements WxareaService {
    public WxareaServiceImpl(Dao dao) {
        super(dao);
    }

    /**
     * 构造查询SQL语句
     */
    public Cnd querySqlBuild(WxArea bean, String pageOrderName, String pageOrderBy) {
        Cnd cnd = Cnd.NEW();
        if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
            cnd.orderBy(pageOrderName, PageUtil.getOrder(pageOrderBy));
        } else {
            cnd.orderBy("area_code", "asc");
        }
        if (bean.getParentId() != null && Strings.isNotBlank(bean.getParentId().toString())) {
            cnd.and("parentId", "=", bean.getParentId());
        }
        if (bean.getLevel() != null && Strings.isNotBlank(bean.getLevel().toString())) {
            cnd.and("level", "=", bean.getLevel());
        }
        if (bean.getName() != null && Strings.isNotBlank(bean.getName().toString())) {
            cnd.and("name", "=", bean.getName());
        }
        if (bean.getWholeName() != null && Strings.isNotBlank(bean.getWholeName().toString())) {
            cnd.and("wholeName", "=", bean.getWholeName());
        }
        if (bean.getLon() != null && Strings.isNotBlank(bean.getLon().toString())) {
            cnd.and("lon", "=", bean.getLon());
        }
        if (bean.getLat() != null && Strings.isNotBlank(bean.getLat().toString())) {
            cnd.and("lat", "=", bean.getLat());
        }
        if (bean.getCityCode() != null && Strings.isNotBlank(bean.getCityCode().toString())) {
            cnd.and("cityCode", "=", bean.getCityCode());
        }
        if (bean.getZipCode() != null && Strings.isNotBlank(bean.getZipCode().toString())) {
            cnd.and("zipCode", "=", bean.getZipCode());
        }
        if (bean.getAreaCode() != null && Strings.isNotBlank(bean.getAreaCode().toString())) {
            cnd.and("areaCode", "=", bean.getAreaCode());
        }
        if (bean.getPinYin() != null && Strings.isNotBlank(bean.getPinYin().toString())) {
            cnd.and("pinYin", "=", bean.getPinYin());
        }
        if (bean.getSimplePy() != null && Strings.isNotBlank(bean.getSimplePy().toString())) {
            cnd.and("simplePy", "=", bean.getSimplePy());
        }
        if (bean.getPerPinYin() != null && Strings.isNotBlank(bean.getPerPinYin().toString())) {
            cnd.and("perPinYin", "=", bean.getPerPinYin());
        }
        return cnd;
    }
}
